package com.example.wan1.base.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.wan1.base.injection.ProxyImpl;
import com.example.wan1.base.mvp.IBaseView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

/***     
 * @Author: zxd
 * @CreateDate: 2020/7/28 16:22
 * @Description:
 */
public abstract class BaseMvpDialogFragment extends DialogFragment implements IBaseView {

    private ProxyImpl mProxyFragment;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mProxyFragment = createProxyFragment();
        mProxyFragment.bindPresenter();
    }

    @Override
    public Context getContext() {
        return getActivity();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mProxyFragment.unBindPresenter();
    }

    private ProxyImpl createProxyFragment() {
        if (mProxyFragment == null) {
            return new ProxyImpl(this);
        }
        return mProxyFragment;
    }
}
